package io;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class ReadAndWriteArray {
	public static void main(String args[]){
		
		File filein = new File("file/arrayin.txt");
		File fileout = new File("file/arrayout.txt");
		try {
			FileReader fin = new FileReader(filein);
			BufferedReader in = new BufferedReader(fin);
			String line;
			line = in.readLine();
			String num[] = line.split(" ");
			int m = Integer.parseInt(num[0]);
			int n = Integer.parseInt(num[1]);
			int arr[][] = new int[m][n];
			for(int i=0;i<m;i++){
				line = in.readLine();
				num = line.split(" ");
				for(int j=0;j<n;j++){
					arr[i][j] = Integer.parseInt(num[j]);
				}
			}
			for(int i=0;i<m;i++){
				for(int j=0;j<n;j++)
					System.out.print(arr[i][j] + " ");
				System.out.println();
			}
			in.close();
			FileWriter fout = new FileWriter(fileout);
			BufferedWriter out = new BufferedWriter(fout);
			out.write(m + " " +n);
			out.newLine();
			for(int i=0;i<6;i++){
				for(int j=0;j<5;j++){
					out.write(arr[i][j] + " ");
				}
				out.newLine();
			}
			System.out.println("Dữ liệu đã được lưu ra file: "+fileout.getName());
			out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
